package com.some;

import java.math.BigInteger;
import java.util.Scanner;

public class JingDong_2 {
    // 思路：根据关系推出各个节点之间的关系，然后进行递推

    public String getPath(String path, String start) {
        for (char c : path.toCharArray()) {
            if (c == 'U') {
                // start =
                //res = start % 2 == 0 ? start / 2 : (start - 1) / 2;
            }
            if (c == 'L') {
                start = multiply(start, "2");
            }
            if (c == 'R') {
                start = addPositive(multiply(start, "2"), "1");
            }
        }
        return start;
    }

    // 字符串相乘
    public String multiply(String num1, String num2) {
        int n1 = num1.length() - 1;
        int n2 = num2.length() - 1;
        if (n1 < 0 || n2 < 0) return "";
        int[] mul = new int[n1 + n2 + 2];

        for (int i = n1; i >= 0; --i) {
            for (int j = n2; j >= 0; --j) {
                int bitmul = (num1.charAt(i) - '0') * (num2.charAt(j) - '0');
                bitmul += mul[i + j + 1]; // 先加低位判断是否有新的进位

                mul[i + j] += bitmul / 10;
                mul[i + j + 1] = bitmul % 10;
            }
        }

        StringBuilder sb = new StringBuilder();
        int i = 0;
        // 去掉前导0
        while (i < mul.length - 1 && mul[i] == 0)
            i++;
        for (; i < mul.length; ++i)
            sb.append(mul[i]);
        return sb.toString();
    }


    /**
     * 无符号相加
     */
    private String addPositive(String s1, String s2) {

        int len1 = s1.length();
        int len2 = s2.length();
        int len = Math.max(len1, len2);
        //暂存计算结果
        int[] result = new int[len];
        //进位符号，为1表示有进位
        int carry = 0;
        for (int i = len - 1; i >= 0; i--) {
            int a1 = i < len1 ? s1.charAt(i) - '0' : 0;
            int a2 = i < len2 ? s2.charAt(i) - '0' : 0;
            //带进位相加
            int a = a1 + a2 + carry;
            result[i] = a % 10;
            //判断当前计算是否产生进位
            carry = a > 9 ? 1 : 0;
        }
        StringBuilder sb = new StringBuilder();
        //有进位则头部加1
        if (carry == 1) sb.append('1');
        for (int i = 0; i < len; i++) sb.append(result[i]);
        return sb.toString();

    }

    /**
     * 无符号相减
     */

    private String subPositive(String s1, String s2) {
        int len1 = s1.length();
        int len2 = s2.length();
        int len = Math.max(len1, len2);
        //暂存计算结果
        int[] result = new int[len];
        int carry = 0;
        for (int i = len - 1; i >= 0; i--) {
            int a1 = i < len1 ? s1.charAt(i) - '0' : 0;
            int a2 = i < len2 ? s2.charAt(i) - '0' : 0;
            //判断低一位计算是否产生借位，如有借位则减1
            if (carry == 1) a1--;
            if (a1 >= a2) {
                //不需要借位，直接相减
                carry = 0;
                result[i] = a1 - a2;
            } else {
                //需要借位，置借位标识并相减
                carry = 1;
                result[i] = a1 + 10 - a2;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) sb.append(result[i]);
        return sb.toString().trim();

    }

    public static void main(String[] args) {
/*        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        double X = scanner.nextDouble();
        String path = scanner.next();*/
        JingDong_2 jingDong = new JingDong_2();
        /*String value = String.valueOf(jingDong.getPath(path, String.valueOf(X)));
        System.out.println(value);*/

        System.out.println(jingDong.multiply("2", "0.5"));
        System.out.println(jingDong.addPositive("1", "3"));
        System.out.println(jingDong.subPositive("5", "2"));

        BigInteger base = new BigInteger("1");
        BigInteger index = new BigInteger("1");
        BigInteger total = new BigInteger("1");

        for (int i = 1; i <= 50; i++) {
            total = total.multiply(index);
            index = index.add(base);
        }

        System.out.println(total);
        System.out.println(new BigInteger("3").divide(new BigInteger("2")));
    }
}
